import java.util.Stack;

class BracketChecker {

    private char[] brackets;

    BracketChecker(String inputString) {
        this.brackets = inputString.toCharArray();
    }


    Boolean areBracketsMatchedAndNestedCorrectly() {
        Stack<Character> result = new Stack<>();
        for (int i = 0; i < this.brackets.length; i++) {
            if (this.brackets[i] == '{' || this.brackets[i] == '[' || this.brackets[i] == '(') {
                result.push(this.brackets[i]);
                continue;
            }
            if (this.brackets[i] == '}' && !result.isEmpty() && result.pop() != '{') {
                return false;
            }
            if (this.brackets[i] == ']' && !result.isEmpty() && result.pop() != '[') {
                return false;
            }
            if (this.brackets[i] == ')' && !result.isEmpty() && result.pop() != '(') {
                return false;
            }
        }

        return result.isEmpty();
    }
}